package com.mall.service.ps;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.ps.PsTimeService;
import com.mall.custom.dao.read.PsTimeReadMapper;
import com.mall.custom.dao.write.PsTimeWriteMapper;
import com.mall.pojo.PsTime;
import com.mall.pojo.PsTimeExample;
import com.mall.pojo.PsTimeExample.Criteria;
@Service
public class PsTimeServiceImpl implements PsTimeService {
	@Autowired
	private PsTimeWriteMapper psTimeWriteMapper;
	@Autowired
	private PsTimeReadMapper psTimeReadMapper;
	@Override
	public Integer insertPsTime(PsTime psTime) {
		psTime.setGmtCreate(new Date());
		psTime.setGmtModify(new Date());
		return this.psTimeWriteMapper.insert(psTime);
	}

	@Override
	public PsTime getPsTimeOnLine(Long userId, int status) {
		PsTimeExample example = new PsTimeExample();
		example.setOrderByClause("id desc");
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		criteria.andStatusEqualTo(status);
		List<PsTime> psTimeList = this.psTimeReadMapper.selectByExample(example);
		PsTime psTime = null;
		if (psTimeList != null && psTimeList.size()>0) {
			psTime = psTimeList.get(0);
		}
		return psTime;
	}

	@Override
	public Integer updatePsTime(PsTime psTime) {
		psTime.setGmtModify(new Date());
		return this.psTimeWriteMapper.updateByPrimaryKey(psTime);
	}

}
